<template>
  <!-- <base-breadcrumb :breadcrumb="!isAudit && !useBaseInfo" :class="{'technical-use-component':useBaseInfo}"> -->
  <div>
  <PromotionDetail v-if="$route.query.noticeType=='602'  || businessType == '827'" :projectQualityTypeId="form.projectQualityTypeId" :goodBusDTO="goodBusDTO" :resolveInfo="resolveInfo || businessType == '827'"></PromotionDetail>
  <TodoReply v-if="$route.query.noticeType=='601'" :id="id" @transfer="getTransfer" :resolveInfo="resolveInfo" :formData="form"></TodoReply>
  <a-spin :spinning="loading.isSubmit">
    <a-card>
      <div class="table-page-search-wrapper">
        <TitleName title="基本信息" />
        <a-form-model
          ref="form"
          :model="form"
          :rules="rules"
          hide-required-mark
          :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
          :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
        >
          <a-row :gutter="24">
            <a-col
              :md="16"
              :sm="16"
            >
              <a-form-model-item
                label="所属单位"
                prop="projectId"
              >
                <org-tree-select
                  v-model="form.projectId"
                  is-auto-select-first
                  :isAutoSelectFirst="this.$route.query.type == 'add'"
                  is-need-auth
                  check-strictly
                  :disabled="editableVersionNumber || this.$route.query.type == 'edit'"

                  :status-set="[1,2,3,4,5,6]"
                  @select="selectOrg"
                  @handleChange="handleChange"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="填报类型"
                prop="reportingType"
              >
                <a-select
                  v-model="form.reportingType"
                  placeholder="请选择"
                  :disabled="editableVersionNumber"
                  @change="handleReportingType"
                >
                  <a-select-option value="0">
                    计划内填报
                  </a-select-option>
                  <a-select-option value="1">
                    计划外填报
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col
              v-if="form.reportingType == '0' && type!== 'view'"
              :md="8"
              :sm="8"
              class="planSelection-class"
            >
              <a-form-model-item
                label="方案名称"
                prop="schemeName"
                required
              >
              <BaseInput
                  v-model="form.schemeName"
                  disabled
                />
                <a-button type="primary" @click="selectionSchemeFn"  :disabled="editableVersionNumber">选择</a-button>
              </a-form-model-item>
            </a-col>
            <a-col
              v-else
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="方案名称"
                prop="schemeName"
                required
              >
                <BaseInput
                  v-model="form.schemeName"
                  :disabled="editableVersionNumber"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="方案类型"
                prop="programTypeId"
                required
              >
              <!-- form.reportingType == '1' && isQualityRoute 计划外和质量-->
                <a-select
                  v-model="form.programTypeId"
                  placeholder="请选择"
                  :disabled="editableVersionNumber || form.reportingType == '0' || isQualityRouteAndJha"
                  @change="changeProgram"
                >
                  <a-select-option
                    v-for="item in typeOption"
                    :key="item.id"
                    :value="item.id"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="工程类别"
                prop="projectQualityTypeId"
                required
              >
                <SelectProjectType v-model="form.projectQualityTypeId" v-if="form.projectId" :id="form.projectId" :defaultCheck="addtable" :disabled="changeEditable || allDisable" @input="clearData" :isAllowClear="false"></SelectProjectType>
              </a-form-model-item>
            </a-col>
            <!-- 只有A/B类方案才有该字段 -->
            <a-col
              :md="24"
              :sm="24"
              v-if="schemeAB">
              <a-form-model-item
                label="危大工程范围"
                prop="dangerDangerDTOS"
                required
              >
              <a-tag v-for="dangerProject in form.dangerDangerDTOS" :key="dangerProject.dangerProjectTypeId" class="mb10" color="#108ee9"  :closable="!(changeEditable || allDisable || !form.projectQualityTypeId)" @close="delDangerProjectType(dangerProject.dangerProjectTypeId)"><Ellipsis :length="50" tooltip>{{ dangerProject.dangerProjectTypeName }}</Ellipsis></a-tag>
              <a-button type="primary" @click="dangerProjectTypFn"  :disabled="changeEditable || allDisable || !form.projectQualityTypeId">选择</a-button>
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                prop="partIdList"
                label="分部分项"
              >
                <SelectTreeSubItem
                  v-model="form.partIdList"
                  :disabled="allDisable || changeEditable"
                  :typeId="form.projectQualityTypeId"
                  :isMultiple="true"
                  :fatherDisabled="true"
                />
              </a-form-model-item>
            </a-col>

            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="现行版本"
                prop="currentVersion"
              >
                <BaseInputNumber
                  v-model="form.currentVersion"
                  :disabled="changeEditable || allDisable"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              v-if="id != ''"
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="报审表编号"
                prop="reviewCode"
              >
                <BaseInput
                  v-model="form.reviewCode"
                  disabled
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="文件编码"
                prop="fileCode"
              >
                <BaseInput
                  v-model="form.fileCode"
                 :disabled="changeEditable || allDisable"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="编制人员"
                prop="compiler"
              >
              <!-- mode="combobox" -->
                <SelectPersonByProject
                  :id="form.branchCompanyId"
                  v-model="form.compiler"
                  :project-id="form.projectId"
                  :show-search="true"
                  :disabled="changeEditable || allDisable"
                  :is-edit="type !== 'view'"
                  option-label-prop="children"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="24"
              :sm="24"
            >
              <a-form-model-item label="方案概况">
                <BaseTextarea
                  v-model="form.programOverview"
                  :disabled="changeEditable || allDisable"
                  :auto-size="{ minRows: 2, maxRows: 6 }"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="正文页数"
                prop="bodyPages"
              >
                <BaseInputNumber
                  v-model="form.bodyPages"
                  :max="10000"
                  :disabled="changeEditable || allDisable"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="附件页数"
                prop="attachmentPages"
              >
                <BaseInputNumber
                  v-model="form.attachmentPages"
                  :max="10000"
                  :disabled="changeEditable || allDisable"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item label="是否涉及重大费用诉求">
                <a-switch
                  v-model="form.whetherMajorExpense"
                  default-checked
                  :disabled="changeEditable || allDisable"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item label="是否为专业分包方案">
                <a-switch
                  v-model="form.whetherProfessionalSubcontracting"
                  default-checked
                  :disabled="editableVersionNumber || allDisable"
                />
              </a-form-model-item>
            </a-col>
            <a-col   v-if="form.whetherProfessionalSubcontracting"
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="分包类型"
                prop="subTypeId"
                required
              >
                <a-select
                  v-model="form.subTypeId"
                  placeholder="请选择"
                  :disabled="changeEditable || allDisable"
                >
                  <a-select-option
                    v-for="item in subcontractType"
                    :key="item.id"
                    :value="item.id"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col
              v-if="form.whetherProfessionalSubcontracting"
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="计划讲评时间"
                prop="evaluationDate"
              >
                <a-date-picker
                  v-model="form.evaluationDate"
                  :disabled="changeEditable || allDisable"
                  @change="(date, dateString) => getTime(date, dateString, 'form', 'evaluationDate')"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="分公司方案审核师"
                prop="branchAuditorUserId"
                required
              >
                <a-select
                  v-model="form.branchAuditorUserId"
                  placeholder="请选择"
                  :disabled="changeBranchAuditorUserId && changeEditable || allDisable"
                >
                <a-spin v-if="fetching" slot="notFoundContent" size="small" />
                  <a-select-option
                    v-for="item in branchCompanyData"
                    :key="item.userId"
                    :value="item.userId"
                  >
                    {{ item.employeeName }}{{item.phone}}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <!-- 施组、A、B类方案 -->
            <a-col
              :md="8"
              :sm="8"
              v-if="schemeSzAB"
            >
              <a-form-model-item
                label="公司方案审核师"
                prop="comAuditorUserId"
                required
              >
                <a-select
                  v-model="form.comAuditorUserId"
                  placeholder="请选择"
                  :disabled=" changeComAuditorUserId && changeEditable || allDisable"
                >
                  <a-select-option
                    v-for="item in companyData"
                    :key="item.userId"
                    :value="item.userId"
                  >
                    {{ item.employeeName }}{{item.phone}}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="预计开始实施时间"
                prop="expectedStartDate"
              >
                <a-date-picker
                  v-model="form.expectedStartDate"
                  :disabled="changeEditable || allDisable"
                  @change="(date, dateString) => getTime(date, dateString, 'form', 'expectedStartDate')"
                  :disabledDate="disabledDateStart"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="预计实施结束时间"
                prop="expectedEndDate"
              >
                <a-date-picker
                  v-model="form.expectedEndDate"
                  :disabled="changeEditable || allDisable"
                  @change="(date, dateString) => getTime(date, dateString, 'form', 'expectedEndDate')"
                  :disabledDate="disabledDateEnd"
                />
              </a-form-model-item>
            </a-col>
            <a-col :md="24" :sm="24">
              <a-form-model-item label="附件上传">
                <fileTable
                :business-code="'TM05'"
                :file-info="changeFileInfo2"
                 :disabled="changeEditable || allDisable"
                @fileArrysData="changeFile1"
                :fileTalbe="fileTalbe1"
              />
              </a-form-model-item>
            </a-col>
            <a-col
            v-if="type=='view'"
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="公司审核师星级"
                prop="comStarLevel"
              >
                <BaseInput
                  v-model="form.comStarLevel"
                  disabled
                />
              </a-form-model-item>
            </a-col>
            <a-col
              v-if="type=='view'"
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="分公司审核师星级"
                prop="branchStarLevel"
              >
                <BaseInput
                  v-model="form.branchStarLevel"
                  disabled
                />
              </a-form-model-item>
            </a-col>
            <a-col
            v-if="type=='view'"
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="方案交底状态"
                prop="confessAuditStatusName"
              >
                <BaseInput
                  v-model="form.confessAuditStatusName"
                  disabled
                />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
    </a-card>
    <!-- <a-card v-if="form.status == 'PAST' || form.status == 'PAST_CHANGE'"> -->
    <a-card v-if="!!form.totalScore && !useBaseInfo && type !=='changeDetail'">
      <title-name title="施组(方案)打分表" />
      <div class="title">
        否决项
      </div>
      <a-table
        :columns="columns"
        :data-source="tableData"
        bordered
        :pagination="false"
      >
        <!-- CheckBox选择框 -->

        <!-- 序号 -->

        <span
          slot="serial"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
      </a-table>
      <div class="title">
        评分项
      </div>
      <a-table
        :columns="columnsScore"
        :data-source="ScoreTableData"
        bordered
        :pagination="false"
      >
        <!-- 序号 -->
        <span
          slot="serial"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
      </a-table>
      <div class="title">
        审核结果
      </div>
      <a-form-model
        :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
        :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
      >
        <a-row>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="审核总分">
              <BaseInput
                v-model="form.totalScore"
                disabled
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="审核结果">
              <BaseInput
                v-model="form.result"
                disabled
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <!-- <a-row>
          <a-col
            :md="16"
            :sm="16"
          >
            <a-form-model-item label="其他评审意见">
              <BaseInput
                v-model="form.opinion"
                type="textarea"
                disabled
              />
            </a-form-model-item>
          </a-col>
        </a-row> -->
      </a-form-model>
    </a-card>

    <a-card v-if="type == 'change' || form.twoReportBusinessVO || isSchemeCategoryA">
      <title-name title="二次报审" />
      <a-form-model
        ref="changeForm"
        :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
        :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
        :model="changeForm"
        :rules="changeRules"
      >
        <a-row>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="专家论证会议时间"
              prop="exportMeetTime"
            >
              <a-date-picker
                v-model="changeForm.exportMeetTime"
                placeholder="请选择专家论证会议时间"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
                :disabled="type !== 'change' && type !=='changeDetail'"

                allow-clear
              />
              <!-- :disabled-date="disabledDateNow" 严瑞超反馈关键用户要取消时间限制20230707-->
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="专家组结论"
              prop="conclusion"
            >
              <a-select
                v-model="changeForm.conclusion"
                placeholder="请选择"
                allow-clear
                :disabled="type !== 'change' && type !=='changeDetail'"
              >
                <a-select-option
                  v-for="item in conclusionData"
                  :key="item.id"
                  :value="item.id"
                >
                  {{ item.name }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col v-if="type == 'view'"
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="报审间隔时间(天)"
              prop="intervaDateNum"
            >
            <BaseInput
                v-model="changeForm.intervaDateNum"
                disabled
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="24"
            :sm="24"
          >
            <a-form-model-item
              label="参加人员"
              prop="people"
            >
              <BaseInput
                v-model="changeForm.people"
                :disabled="type !== 'change' && type !=='changeDetail'"
                type="textarea"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="预计开始实施时间"
              prop="implementationDate"
            >
              <a-date-picker
                v-model="changeForm.implementationDate"
                :disabled="type !== 'change' && type !=='changeDetail'"
                placeholder="请选择预计实施时间"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
                allow-clear
                :disabledDate="disabledDateStart2"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="预计实施结束时间"
              prop="implementationEndDate"
            >
              <a-date-picker
                v-model="changeForm.implementationEndDate"
                :disabled="type !== 'change' && type !=='changeDetail'"
                placeholder="预计实施结束时间"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
                allow-clear
                :disabledDate="disabledDateEnd2"
              />
            </a-form-model-item>
          </a-col>
          <a-col :md="8" :sm="8">
              <!-- 实施责任人插槽 -->
              <a-form-model-item label="实施责任人"  prop="implementationUserId">
                <!-- 查看西南公司下所有人 -->
               <ASelectOrgPeople v-model="changeForm.implementationUserId" :disabled="type !== 'change' && type !=='changeDetail'" :show-search="true" :orgId="'53085e2c9f1f4685801ef31994f57c49'" @onSelectChange="setimplementationUserName"></ASelectOrgPeople>
            </a-form-model-item>
            </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="24"
            :sm="24"
          >
            <a-form-model-item
              label="附件上传"
              prop="fileArrays"
              style="display: flex"
              class="filetalbe"
            >
              <fileTable
                :business-code="'TM05'"
                :file-info="changeFileInfo"
                :disabled="type !== 'change' && type !=='changeDetail'"
                @fileArrysData="changeFile"
                :fileTalbe="fileTalbe2"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-card>
    <!-- changeInfoForm.changeReason || changeInfoForm.changeFileInfoVOS || form.versionNumbe*1>1  有值显示。版本大于1显示-->
    <a-card  v-if="type == 'changeDetail'|| changeInfoForm.changeReason  || (form.versionNumber*1>1 && type!='view')">
      <title-name title="变更信息" />
      <a-form-model
        ref="changeInfoForm"
        :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
        :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
        :model="changeInfoForm"
        :rules="changeInfoRules"
      >
      <a-row>
          <a-col :md="24" :sm="24">
            <a-form-model-item label="变更内容及理由" prop="changeReason">
             <BaseInput v-model="changeInfoForm.changeReason" type="textarea" :disabled="allDisable || type == 'view'" :is-close="type !== 'view'" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :md="24" :sm="24">
            <a-form-model-item label="佐证材料">
                <upload-list
                  :business-code="'TM05'"
                  :upload-arrys.sync="changeInfoForm.changeFileInfoVOS"
                  :is-close="type !== 'view'"
                  :disabled="allDisable || type == 'view'"
                  multiple
                />
              </a-form-model-item>
          </a-col>
        </a-row>
    </a-form-model>
    </a-card>
    </a-spin>
    <div class="tool-btns page-btn-right-top" v-if="!allDisable && !useBaseInfo">
      <!-- historicalData历史数据不能打印 -->
      <template v-if="form.programTypeName=='A'">
        <print-button
        v-if="(form.status == 'PAST' || form.status == 'PAST_CHANGE') && !historicalData"
        button-text="评价表打印"
        :before-print-fn="managementPrint"
      />
      <print-button
      v-if="(form.status == 'PAST' || form.status == 'PAST_CHANGE' || form.status == 'DRAFT_CHANGE' || form.status == 'REJECTED' || form.status == 'SUBMITTED_CHANGE' ||  form.status == 'REJECTED_CHANGE') && !historicalData"
        class="ml12"
        button-text="打印一次报审表"
        :before-print-fn="approvalDetailsOnePrint"
      />
      <print-button
      v-if="(form.status == 'PAST_CHANGE') && !historicalData"
        class="ml12"
        button-text="打印二次报审表"
        :before-print-fn="approvalDetailsPrint"
      />
    </template>
    <template v-else>
      <print-button
        v-if="(form.status == 'PAST' || form.status == 'PAST_CHANGE') && !historicalData"
        button-text="评价表打印"
        :before-print-fn="managementPrint"
      />
      <print-button
      v-if="(form.status == 'PAST' || form.status == 'PAST_CHANGE') && !historicalData"
        class="ml12"
        button-text="报审表打印"
        :before-print-fn="approvalDetailsPrint"
      />
    </template>
      <!-- 二次报审的保存草稿功能 -->
      <a-button
      v-if="type == 'change'"
        :loading="loading.isDraft"
        class="ml12"
        type="primary"
        @click="saveTwo('DRAFT_CHANGE')"
      >
        保存草稿
      </a-button>
      <!-- versionNumber版本号大于2就不能删除 -->
      <a-button
        v-if="id != '' && type !== 'view' && form.status == 'DRAFT' && form.versionNumber*1<2"
        class="ml12"
        type="danger"
        @click="discard(form)"
      >
        删除草稿
      </a-button>
      <a-button
        v-if="type !== 'view' && type !== 'change'"
        :loading="loading.isDraft"
        class="ml12"
        type="primary"
        @click="save"
      >
        保存草稿
      </a-button>
      <a-button
        v-if="type !== 'view'"
        :loading="loading.isSubmit"
        class="ml12"
        type="primary"
        @click="submit"
      >
        提交
      </a-button>
      <a-button
        v-if="checkVisibleInDetail"
        class="ml12"
        type="primary"
        @click="handleClose()"
      >
        返回
      </a-button>
    </div>
    <selectApprover
      :business-id="businessId"
      :process-config="setProcessConfig"
    />
    <SelectionScheme :isQualityRoute="isQualityRoute" :visible="selectionSchemeVisible" :typeOption="typeOption" @cancel="selectionSchemeVisible = false" :projectId="form.projectId" @confirmSingle="confirmSingle"></SelectionScheme>
    <DangerousProject v-if="schemeAB" :visible="dangerousProjectVisible" :projectQualityTypeId="form.projectQualityTypeId" @cancel="cancelDangerousProject" :projectType="projectType" :parSelectedRows="form.dangerDangerDTOS"></DangerousProject>
    </div>
  <!-- </base-breadcrumb> -->
</template>

<script>
import SelectPersonByProject from '@/components/Select/SelectPersonByProject'
import UploadList from '@/components/UploadList'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import TitleName from '@/components/TitleName/index.vue'
import { getOption, addList, editList, deleteList, getDetails, managementPrint, approvalDetailsPrint,printAbyOne,getConstructionProgramHistoryById,getProgramByGoodId} from '@/api/technical/approval'
import { listOption } from '@/api/technical/approvalPlan'
import { checkVisibleInDetail } from '@/utils/util'
import printButton from '@/components/BasePrintButton' // 打印
import fileTable from './fileTable.vue'
import SelectionScheme from './selectionScheme.vue'   //选择方案
import PromotionDetail from './promotionDetail.vue'   //推优(项目总工)业务待办
import TodoReply from './todoReply.vue'   //回复上报方案人_业务待办
import SelectTreeSubItem from '@/components/Select/SelectTreeSubItem'
import { fileInfoVOListColumns} from './model.js'
import SelectProjectType from '@/components/Select/SelectProjectType' // 工程类别
import { getReviewerList } from '@/api/technical/review'
import DangerousProject from './dangerousProject'
import ASelectOrgPeople from '@/components/Select/ASelectOrgPeople.vue'
import { Ellipsis } from '@/components'
import moment from 'moment'
const fileColumns = [
  {
    title: '序号',
    width: '65px',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '文件名称',
    width: '200px',
    dataIndex: 'fileName'
  },
  {
    title: '文件',
    dataIndex: 'fileList'
  },
  {
    title: '操作',
    dataIndex: 'operation',
    width: '120px',
    scopedSlots: { customRender: 'operation' }
  }
]
export default {
  name: 'a' + Date.now(),
  components: {
    TitleName,
    SelectSubCompany,
    SelectProject,
    UploadList,
    SelectPersonByProject,
    printButton,
    fileTable,
    SelectTreeSubItem,
    SelectionScheme,
    PromotionDetail,
    TodoReply,
    SelectProjectType,
    DangerousProject,
    ASelectOrgPeople,
    Ellipsis
  },
  data() {
    const validReportType = (rule, value, callback) => {
      const validKey = this.form.reportingType === '1' ? 'programTypeId' : 'planSelection'
      if (!this.form[validKey]) {
        callback(new Error('请选择'))
      } else {
        callback()
      }
    }
    return {
      fileColumns,
      fileInfoVOListColumns,
      htmlData: '',
      htmlDatas: '',
      checkVisibleInDetail: checkVisibleInDetail(this),
      loading: {
        isDraft: false,
        isSubmit: false
      },
      selectionSchemeVisible:false,
      form: {
        reportingType: '0',
        compiler: '',
        branchComId: '',
        projectId: '',
        fileInfoVOList: [],
        programTypeId: '',
        schemeName: '',
        projectQualityTypeId:null,
        newFileIds:{},
        dangerDangerDTOS:[], //危大工程范围数据

      },
      editorObj:{
        filledUserId:this.$userInfo().id,
        name:this.$userInfo().name,
        submitDate: this.$dateFormat(new Date(), 'D'),
      },
      fileTalbe1: [
          { id:1,fileName: '施工方案电子版', fileList: [] },
          { id:2,fileName: '相关图纸变更', fileList: [] },
          { id:3,fileName: '相关会签表', fileList: [] },
          { id:4,fileName: '其他', fileList: [] },
      ],
      fileTalbe2: [
              { id: 1, fileName: '修改后的专项施工方案', fileList: [] },
              { id: 2, fileName: '专家论证会议签到表及现场会议照片', fileList: [] },
              { id: 3, fileName: '专家论证审查意见表', fileList: [] },
              { id: 4, fileName: '其他', fileList: [] }
            ],
      rules: {
        evaluationDate: [{ required: true, message: '请选择', trigger: 'change' }],
        partIdList: [{ required: true, message: '请选择', trigger: 'change' }],
        branchComId: [{ required: true, message: '请选择', trigger: 'change' }],
        projectId: [{ required: true, message: '请选择', trigger: 'change' }],
        reportingType: [{ required: true, message: '请选择', trigger: 'change' }],
        schemeName: [{ validator: validReportType, trigger: 'change' }],
        programTypeId: [{ validator: validReportType, trigger: 'change' }],
        currentVersion: [{ required: true, message: '请输入', trigger: 'change' }],
        reviewCode: [{ required: true, message: '请输入', trigger: 'change' }],
        fileCode: [{ required: true, message: '请输入', trigger: 'change' }],
        compiler: [{ required: true, message: '请选择', trigger: 'change' }],
        programOverview: [{ required: true, message: '请输入', trigger: 'change' }],
        bodyPages: [{ required: true, message: '请输入', trigger: 'change' }],
        attachmentPages: [{ required: true, message: '请输入', trigger: 'change' }],
        schemeName: [{ required: true, message: '请输入', trigger: 'change' }],
        expectedStartDate:[{ required: true, message: '请选择', trigger: 'change' }],
        expectedEndDate:[{ required: true, message: '请选择', trigger: 'change' }],
        subTypeId:[{ required: true, message: '请选择', trigger: 'change' }],
        branchAuditorUserId:[{ required: true, message: '请选择', trigger: 'change' }],
        comAuditorUserId:[{ required: true, message: '请选择', trigger: 'change' }],
        projectQualityTypeId:[{ required: true, message: '请选择', trigger: 'change' }],
        dangerDangerDTOS:[{ required: true, message: '请选择', trigger: 'change' }],

      },
      planItemList: [], // 计划项列表
      type: '',
      id: '',
      historicalData:false, //是否历史数据
      disabled: false,
      typeOption: [],
      companyData:[],  //公司审核师数据
      branchCompanyData:[], //分公司审核师数据
      tableData: [],
      ScoreTableData: [],
      selectedRowKeys: '',
      selectedRows: '',
      totalScore: '',
      result: '',
      vetoHeaderId: '',
      columnsScore: [],
      columns: [],
      scoreInformation: '',
      scorecount: '',

      changeForm: {
        exportMeetTime: '',
        implementationDate: '',
        conclusion: undefined,
        people: ''
      },
      changeRules: {
        exportMeetTime: [{ required: true, message: '请选择', trigger: 'change' }],
        implementationDate: [{ required: true, message: '请选择', trigger: 'change' }],
        implementationEndDate: [{ required: true, message: '请选择', trigger: 'change' }],
        conclusion: [{ required: true, message: '请选择', trigger: 'change' }],
        people: [{ required: true, message: '请输入', trigger: 'blur' }],
        implementationUserId: [{ required: true, message: '请选择', trigger: 'change' }],
      },
      changeInfoForm:{
        changeFileInfoVOS:[],
        changeReason:null,
      },
      changeInfoRules: {
        changeFileInfoVOS: [{ type: 'array', required: true, message: '请上传附件', trigger: 'blur' }],
        changeReason: [{ required: true, message: '请输入', trigger: 'blur' }],

      },
      conclusionData: [
        // 通过、不通过、修改后通过
        // {name: '通过', id: 'past'},
        // {name: '不通过', id: 'reject'},
        // {name: '修改后通过', id: 'afterpast'}
      ],
      changeFileInfo: {},
      changeFileInfo2: {},
            //获取流程配置值
      processConfig: null,
      //点击提交发送流程配置值
      setProcessConfig: null,
      businessId: null,
      allDisable:false, //禁用所有
      subcontractType:[], //分包类型
      dangerousProjectVisible:false,
      projectType:'1', //危大工程范围传参，A 传1 超危大工程，B 传2 危大工程
      goodBusDTO:{},
      sendUser: [],//实施责任人列表
      noticeType:null,  //待办编码
      fetching:false,
      businessType:null,
      changeBranchAuditorUserId:true, //二次报审分公司方案审核师是否有数据
      changeComAuditorUserId:true, //二次报审公司方案审核师是否有数据
    }
  },
  props: {
    isAudit: {
      // 是否作为审批详情
      type: Boolean,
      default: false
    },
    // 是否作为组件
    useBaseInfo: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    isAudit: {
      immediate: true,
      handler(val) {
        if (val) {
          this.$nextTick(() => {
            this.type = 'view'
            this.allDisable = true;
          })
        }
      },
    },
  'type':{
    immediate: true,
     async handler(val) {
       if(val == 'change'){
         //获取通过获取流程配置值
         this.processConfig = await this.$getConfigFn('technology_construction_plan_a_two');
       }
      }
    },
    'form.programTypeId':{
      immediate: true,
      handler(val) {
        if (val) {
          this.setConfig(val);
           if(val == '634285858551369728'){
            this.projectType = '1';
           }else if(val == '634285886040838144'){
            this.projectType = '2';
           }
        }
      }
    },
    'form.projectQualityTypeId':{
      immediate: true,
      handler(val,old) {
        if (val && old) {
          this.$set(this.form, 'partIdList',[])
        }
      }
    },
  },
  computed: {
  // 是否是业务待办查看处理信息
    resolveInfo: {
      get() {
        return this.$route.query?.resolveInfo === 'true'
      },
      set() {}
    },
    editable() {
      return this.$route.query.type == 'add' || this.$route.query.type == 'edit'
    },
    editableVersionNumber() {
      let flag  = false;
      if(this.type == 'add'){
        flag = false;   //新增可以编辑
      }
       else if(this.type == 'edit'){
        if(this.form.versionNumber*1>1){  //编辑时，且版本大于1不能编辑
          flag = true
        }else{
          flag = false
        }
      }else{   //其他情况不能修改
        flag = true
      }
      return flag;
    },
    addtable() {
      return this.$route.query.type == 'add';
    },
    isSchemeCategoryA(){
       return this.$route.query.isSchemeCategoryA == 1 ? true : false;
    },
    isQualityRoute(){  //是否是质量路由
      let flag = this.$route.query.isQualityRoute*1 ===1? false : true;
       return flag;
    },
    isQualityRouteAndJha(){  //计划外和路由为质量
      let flag = this.form.reportingType == '1' && this.isQualityRoute?true:false;
      return flag;
    },
    changeEditable(){
      let type = this.$route.query.type,isSchemeCategoryA = this.$route.query.isSchemeCategoryA,
      flag = false;
      if(type == 'view' || isSchemeCategoryA){    //查看，或者为方案A，
        flag = true
      }else if(type == 'changeDetail' && !isSchemeCategoryA){  //变更并且方案不为A
        flag = false
      }
      else if(type == 'change'){
        flag = true
      }else{
        flag = false
      }
      return flag;
    },
    //方案是否是A,B，施组
    schemeSzAB(){
      let programTypeId = this.form.programTypeId,
      schemeArr = ['634286036096258048','634285858551369728','634285886040838144'],  //施组，A,B
      flag = schemeArr.includes(programTypeId);
      return flag
    },
    //方案是否是A,B
    schemeAB(){
      let programTypeId = this.form.programTypeId,
      schemeArr = ['634285858551369728','634285886040838144'], //A,B
      flag = schemeArr.includes(programTypeId);
      return flag
    }
  },
  created() {
    this.type = this.$route.query.type;

    this.id = this.$route.query.businessId || '';
    this.noticeType =this.$route.query.noticeType || null;
    this.historicalData = this.$route.query.historicalData || false;   //是否是点击历史版本查看历史数据
    this.businessType =  this.$route.query.businessType || null;
    if(this.noticeType=='601'){   //推优要用接口返回id来查询
    }else if(this.businessType== '827'){
      this.getProgramByGoodIdFn();
    }
    else{
      this.id = this.$route.query.id || '';
      this.getDetails()
    }
    this.clickTypeOption()
    let type = this.$route.query.type;
    this.allDisable = type == 'allDisable';
    this.getReviewerListFn();
    if(this.isQualityRoute){
      this.editorObj.qualityDataStaus = 1;
    }
  },
  methods: {
    //切换方案名称
    changeProgram(){
      this.form.dangerDangerDTOS = [];  //切换方案清空危大工程范围
    },
    /**
     * @description: 时间禁用
     * @param {object} current 当前时间对象
     * @return {boolean}
     */
    disabledDateNow(current) {
      return current && current <moment().subtract(1, "days"); //当天之前的不可选，不包括当天
    },
    //
    clearData(data){
       this.form.dangerDangerDTOS = [];
    },
    setimplementationUserName(data){
     this.$set(this.form, 'implementationName', data.name)
    },
    //施组方案推优审批调过来，要用businessId 去重新请求id，来查询详情数据
    getProgramByGoodIdFn(){
       if(this.id){
        getProgramByGoodId({id:this.id}).then((res)=>{
          if(res.code == 200){
             this.id = res.data?.id;
             this.getDetails()
          }
        })
       }
    },
    //选择危大工程
    dangerProjectTypFn(){
       this.dangerousProjectVisible = true;
    },
    delDangerProjectType(removedTag){
      const newList = this.form.dangerDangerDTOS.filter(item => item.dangerProjectTypeId !== removedTag);
      this.form.dangerDangerDTOS = newList;
    },
    cancelDangerousProject(flag,data){
      this.dangerousProjectVisible = flag;
      let newData = [];
      if(data){
        data.map((item)=>{
          newData.push({
            dangerProjectTypeId:item.id?item.id:item.dangerProjectTypeId,
            dangerProjectTypeName:item.desc?item.desc:item.dangerProjectTypeName
          })
        })
        this.form.dangerDangerDTOS = newData || [];
      }
    },
    //获取公司审核师
    getReviewerListFn(){
      let params = {
        orgId:'53085e2c9f1f4685801ef31994f57c49',   //直属机关orgId
        pageNo:1,
        pageSize:10000
      }
      getReviewerList(params).then((res)=>{
         if(res.code == '200'){
          this.companyData = res.data
         }
      })
    },
    //获取分公司审核师
    getBranchCompanyListFn(org){
      this.branchCompanyData = [];
      if(this.type == 'add'){
        this.$set(this.form, 'branchAuditorUserId',null)
      }
      let params = {
        orgId:org,   //直属机关orgId
        pageNo:1,
        pageSize:10000
      }
      getReviewerList(params).then((res)=>{
        if(res.code == '200'){
          this.branchCompanyData = res.data
          this.fetching = false;
         }
      })
    },
    //选择试验计划
    selectionSchemeFn(){
      this.selectionSchemeVisible = true;
    },
    confirmSingle(data){
      this.$set(this.form, 'schemeName', data.schemeName)
      this.$set(this.form, 'planSelection', data.id)
      this.$set(this.form, 'programTypeId', data.schemeCategoryId)
      this.selectionSchemeVisible = false;
      this.form.dangerDangerDTOS = [];  //切换方案清空危大工程范围
    },
    selectOrg(val) {
      this.fetching = true;
      this.form.branchComId = val[val.length - 2].orgId
      this.getOption()
      let branchCompanyOrgId = val[0].orgId;   //获取分公司orgiD
      this.getBranchCompanyListFn(branchCompanyOrgId)
    },
    handleChange() {
      this.$set(this.form, 'partIdList', null)
    },
    //设置流程管理的值
   async setConfig(val){
      let findName = this.typeOption.find((item=>item.id === val)).name;
      let sureName=  this.type =='change'?'TwoA':findName;
      let configObj = {
        'A':'technology_construction_plan_a',
        'B':'technology_construction_plan_b',
        'C':'technology_construction_plan_cd',
        'D':'technology_construction_plan_cd',
        '施组':'technology_construction_plan_sz',
        'TwoA':'technology_construction_plan_a_two'
      };
     //获取通过获取流程配置值
      this.processConfig = await this.$getConfigFn(configObj[sureName]);
    },
    changeCompany(e) {
      this.$set(this.form, 'partIdList', null)
    },
    getTime(date, dateString, type, name) {
      this[type][name] = dateString
      console.log(this[type][name])
    },
    managementPrint() {
      let that = this
      return new Promise((resolve, reject) => {
        let data = { id: this.id }
        managementPrint(data)
          .then((res) => {
            if (res.code == 200 || res.data.code === 200) {
              resolve(res.data.content)
            }
          })
          .catch((e) => {
            that.$message.error(e)
          })
          .finally(() => {
            resolve()
          })
      })
    },
    approvalDetailsPrint() {
      let that = this
      return new Promise((resolve, reject) => {
        let data = { id: this.id }
        approvalDetailsPrint(data)
          .then((res) => {
            if (res.code == 200 || res.data.code === 200) {
              resolve(res.data.content)
            }
          })
          .catch((e) => {
            that.$message.error(e)
          })
          .finally(() => {
            resolve()
          })
      })
    },
    //打印一次报审表
    approvalDetailsOnePrint(){
      let that = this
      return new Promise((resolve, reject) => {
        let data = { id: this.id }
        printAbyOne(data)
          .then((res) => {
            if (res.code == 200 || res.data.code === 200) {
              resolve(res.data.content)
            }
          })
          .catch((e) => {
            that.$message.error(e)
          })
          .finally(() => {
            resolve()
          })
      })
    },
    discard(record) {
      let _this = this
      this.$confirm({
        title: '温馨提示',
        content: '确定是否删除数据？',
        okText: '确认',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          return deleteList({ id: record.id }).then((res) => {
            _this.$message.success('删除成功')
            _this.handleClose()
          })
        },
        onCancel() {}
      })
    },
    handleReportingType() {
      this.form.planSelectionId = undefined
      this.form.planSelection = undefined
      this.form.schemeName = undefined
      this.form.programTypeId = undefined
      if(this.isQualityRouteAndJha){
        this.form.programTypeId = this.typeOption?.find(item=>item.name=='D')?.id || '';
      }
    },
    handleProgramTypeId() {
      if (this.form.reportingType == 0) {
        const obj = this.planItemList.find((item) => {
          return item.id == this.form.planSelection
        })
        this.form.schemeName = obj.constructionName
        this.form.programTypeId = obj.planType.id
      }

      // console.log(this.form.programTypeId)
      // console.log(this.form.schemeName)
    },
    handleProjectChanged() {
      this.$set(this.form, 'partIdList', null)
      this.getOption()
    },
    handleFileUploaded(list) {
      this.form.fileInfoVOList = [...list]
    },
    handleClose() {
      if (this.isAudit) {
        window.close()
      } else {
        this.$multiTab.close(this.$route.fullpath)
      }
    },
    listOption() {
      listOption({ type: '5' }).then((res) => {
        this.typeOption = res.data || [];
        if(this.typeOption.length){
          this.typeOption.map((item)=>{
            item.label = item.name;
            item.value = item.id;
          })
        }
      })
      listOption({ type: '8' }).then((res) => {
        this.conclusionData = res.data
      })
      listOption({ type: '15' }).then((res) => {
        this.subcontractType = res.data
      })
    },
    clickTypeOption() {
      this.listOption()
    },
    getOption() {
      const { projectId } = this.form
      if (!projectId) return
      const params = {
        projectId: projectId
      }
      getOption(params).then((res) => {
        if (res.code === 200) {
          this.planItemList = res.data
        }
      })
    },
    save() {
      // this.$refs.form.validate((valid) => {
        // if (!valid) return
        // if(!this.form.newFileIds['1'] || this.form.newFileIds['1']?.length==0){
        //   this.$message.warning('请上传施工方案电子版');
        //   return
        // }
        // if(!this.form.newFileIds['3'] || this.form.newFileIds['3'].length==0){
        //   this.$message.warning('请上传相关会签表')
        //   return
        // }

        if (!this.form.schemeName){
          this.$message.warning('请选择方案名称');
          return
        }
        if (this.form.reportingType == '1' && !this.form.programTypeId){
          this.$message.warning('请选择方案类型');
          return
        }
        if (this.loading.isDraft) return
        this.loading.isDraft = true
        this.form.auditStatus = '0'
        //二次报审变更
        if(this.$route.query.type =='changeDetail' && this.isSchemeCategoryA){
          this.form.auditStatus = '4'
        }else{
          this.form.auditStatus = '0'
        }
        if (this.id) {
          this.form.id = this.id
          let param = {
                ...this.form,
                ...this.changeInfoForm,
                ...this.changeForm,
                ...this.editorObj
                }
          editList(param)
            .then((res) => {
              this.loading.isDraft = false
              if (res.code == '200') {
                this.$message.success('修改成功')
                this.handleClose()
              }
            })
            .catch(() => {
              this.loading.isDraft = false
            })
        } else {
          let param = {
                ...this.form,
                ...this.editorObj
                }
          addList(param)
            .then((res) => {
              this.loading.isDraft = false
              if (res.code == '200') {
                this.$message.success('新增成功')
                this.handleClose()
              }
            })
            .catch(() => {
              this.loading.isDraft = false
            })
        }
      // })
    },
    // 二次报审保存草稿
    saveTwo(status){
      this.loading.isDraft = true
        this.form.auditStatus = '4'
          const param = {
            ...this.form,
            ...this.changeForm,
            ...this.editorObj
          }
          editList(param)
            .then((res) => {
              this.loading.isDraft = false
              if (res.code == '200') {
                this.$message.success('提交成功')
                this.handleClose()
              }
            })
            .catch(() => {
              this.loading.isSubmit = false
            })
    },
    sureSubmit(param){
      this.loading.isSubmit = true;
      this.form.id = this.id
        editList(param)
          .then((res) => {
            this.loading.isSubmit = false;
            if (res.code == '200') {
              this.$message.success('变更成功')
              this.businessId = res.data.id;
              this.setProcessConfig = this.processConfig;
              // if(!this.setProcessConfig){
              //     this.handleClose()
              // }
            }
          })
          .catch(() => {
            this.loading.isSubmit = false
          })
    },
    submit() {
      this.setProcessConfig = null;
      if (this.$route.query.type == 'change') {
        this.$refs.changeForm.validate((valid) => {
          if (!valid) return
          if (this.loading.isSubmit) return
          this.form.auditStatus = '5'
          if(!this.form.branchAuditorUserId){
            this.$message.warning('请选择分公司方案审核师');
            return
          }
          if(!this.form.comAuditorUserId){
            this.$message.warning('请选择公司方案审核师');
            return
          }
          this.loading.isSubmit = true
          const param = {
            ...this.form,
            ...this.changeForm,
            ...this.editorObj
          }
          editList(param)
            .then((res) => {
              this.loading.isSubmit = false
              if (res.code == '200') {
                this.$message.success('提交成功')
                this.businessId = res.data.id;
                this.setProcessConfig = this.processConfig;
              }
            })
            .catch(() => {
              this.loading.isSubmit = false
            })
        })
        return
      }
      if(this.$route.query.type == 'changeDetail'){   //变更
        if(this.isSchemeCategoryA){
              this.$refs.changeForm.validate((valid2) => {
              if (!valid2) return
                if(!this.changeInfoForm.changeFileInfoVOS.length){
                this.$message.warning('请上传附件上传');
                return
              }
              if(!this.form.branchAuditorUserId){
                this.$message.warning('请选择分公司方案审核师');
                return
              }
              if(!this.form.comAuditorUserId){
                this.$message.warning('请选择公司方案审核师');
                return
              }
                this.form.auditStatus = '5'
                let param = {
                ...this.form,
                ...this.changeInfoForm,
                ...this.changeForm,
                ...this.editorObj
                }
                this.sureSubmit(param)
                })
        return
      }else{
        this.$refs.form.validate((valid) => {
          if(valid){
            this.$refs.changeInfoForm.validate((valid1) => {
             if (!valid1) return
              this.form.auditStatus = '1'
              if(!this.form.newFileIds['1'] || this.form.newFileIds['1']?.length==0){
                this.$message.warning('请上传施工方案电子版');
                return
              }
              if(!this.form.newFileIds['3'] || this.form.newFileIds['3'].length==0){
                this.$message.warning('请上传相关会签表')
                return
              }
              if(!this.changeInfoForm.changeFileInfoVOS.length){
              this.$message.warning('请上传附件上传');
              return
             }
             let param2 = {
              ...this.form,
              ...this.changeInfoForm,
              ...this.editorObj
            }
            this.sureSubmit(param2)
            })
          }
        })

      }
        return

      }


      this.$refs.form.validate((valid) => {
        if (!valid) return
        if (this.loading.isSubmit) return
        if(!this.form.newFileIds['1'] || this.form.newFileIds['1']?.length==0){
          this.$message.warning('请上传施工方案电子版');
          return
        }
        if(!this.form.newFileIds['3'] || this.form.newFileIds['3'].length==0){
          this.$message.warning('请上传相关会签表')
          return
        }
        this.loading.isSubmit = true
        this.form.auditStatus = '1'
        const param = {
            ...this.form,
            ...this.editorObj
          }
        if (this.id) {
          this.form.id = this.id
          // if (!this.changeInfoForm.changeReason){
          //   this.$message.warning('请输入变更内容及理由')
          //   this.loading.isSubmit = false
          //   return
          // }
          editList(param)
            .then((res) => {
              this.loading.isSubmit = false
              if (res.code == '200') {
                this.$message.success('修改成功')
                 this.businessId = res.data.id;
                this.setProcessConfig = this.processConfig;
                if(!this.setProcessConfig){
                    this.handleClose()
                }
              }
            })
            .catch(() => {
              this.loading.isSubmit = false
            })
        } else {
          addList(param)
            .then((res) => {
              this.loading.isSubmit = false
              if (res.code == '200') {
                this.$message.success('新增成功')
                this.businessId = res.data.id;
                this.setProcessConfig = this.processConfig;
                if(!this.setProcessConfig){
                    this.handleClose()
                }
              }
            })
            .catch(() => {
              this.loading.isSubmit = false
            })
        }
      })
    },
    initTable(res) {
      // 否决项

      this.columns = res.data.vetoHeader
      this.tableData = res.data.vetoContent
      console.log('res.data.vetoContent',res.data.vetoContent)
      if (!this.columns || !this.tableData) return
      this.columns.unshift({
        dataIndex: 'serial',
        formId: null,
        title: '序号',
        code: '0',
        sort: 0,
        inputType: null,
        scopedSlots: { customRender: 'serial' }
      })
      let obj = {}
      this.columns.forEach((item) => {
        obj = this.columns.filter((items) => items.code == '9')
      })
      // console.log(obj)
      this.vetoHeaderId = obj[0].dataIndex
      obj[0].scopedSlots = { customRender: 'checkbox' }
      // console.log(this.columns)

      // 评分项
      res.data.scoreHeader.forEach((item, index) => {
        if (item.sort == 4) {
          res.data.scoreHeader.splice(index, 1)
        }
      })
      this.columnsScore = res.data.scoreHeader
      this.ScoreTableData = res.data.scoreContent
      // this.formDatas = cloneDeep(res.data.scoreHeader)
      this.columnsScore.unshift({
        dataIndex: 'serial',
        formId: null,
        title: '序号',
        code: '0',
        sort: 0,
        inputType: null,
        scopedSlots: { customRender: 'serial' }
      })

      let objScore = {}
      this.columnsScore.forEach((item) => {
        objScore = this.columnsScore.filter((items) => items.code == '10')
      })
      objScore[0].scopedSlots = { customRender: 'score' }
      this.scorecount = objScore[0].dataIndex

      let information = {}
      this.columnsScore.forEach((item) => {
        information = this.columnsScore.filter((items) => items.code == '9')
      })
      try {
        information[0].scopedSlots = { customRender: 'information' }
        this.scoreInformation = information[0].dataIndex
      } catch (e) {
        console.error(e)
      }
    },
    getTransfer(id){
      this.id = id;
      this.getDetails();
    },
    getDetails() {
      if (this.id) {
         this.loading.isSubmit = true;
        let api = this.historicalData? getConstructionProgramHistoryById : getDetails;
        api({ id: this.id }).then((res) => {
          this.form = {
            ...this.form,
            ...res.data
          }
          this.loading.isSubmit = false;
          this.form.programTypeId = res.data.programTypeId
          this.form.planSelection = res.data.planSelectionId
          this.form.whetherMajorExpense = res.data.whetherMajorExpense === 'true' ? true : false
          this.form.whetherProfessionalSubcontracting = res.data.whetherProfessionalSubcontracting === 'true' ? true : false
          this.goodBusDTO = this.form?.goodBusDTO;
          this.form.dangerDangerDTOS = res.data.dangerDangerDTOS || []
          this.form.newFileInfoVOS['4'] = res.data.newFileInfoVOS && res.data.newFileInfoVOS['4'] || [];
          if(this.type=='change' || this.type=='changeDetail' && this.isSchemeCategoryA){  //对于二次报审没数据的放开特殊处理
            this.changeBranchAuditorUserId = this.form.branchAuditorUserId?true:false;
            this.changeComAuditorUserId = this.form.comAuditorUserId?true:false;
          }
          if(res?.data?.branchComId){
            this.getBranchCompanyListFn(res.data.branchComId)
          }
          this.$nextTick(() => {
            this.form.projectId = res.data.projectId
            this.$nextTick(() => {
              this.form.compiler = res.data.compiler
            })
            this.getOption()
          })
          // if (this.type !== 'change') {
            this.initTable(res)
          // }

          // this.changeFileInfo = {1: res.data.fileInfoVOList}
          // this.changeFile(this.changeFileInfo)
          if (res.data.twoReportBusinessVO) {
            this.changeForm = res.data.twoReportBusinessVO
            this.changeFileInfo = res.data.twoReportBusinessVO.fileInfoVOS
            this.changeFile(this.changeFileInfo)
          }
          if(res.data.changeReason){
            this.changeInfoForm.changeReason = res.data.changeReason;
            this.changeInfoForm.changeFileInfoVOS = res.data.changeFileInfoVOS || [];
          }
          this.changeFileInfo2 = res.data.newFileInfoVOS
          if(res.data.newFileInfoVOS['1']){
            this.changeFile1( this.changeFileInfo2)
          }
          //this.changeFile(this.changeFileInfo)
          // 派发一个事件 以供父组件使用form
          this.$emit('success',  this.form)
        })
      }
    },
    changeFile(list) {
      const obj = {}
      for (let idx in list) {
        const item = list[idx]
        obj[idx] = item && item.map((v) => v.commonId)
      }
      this.changeForm.fileIds = obj
    },
    changeFile1(list){
      const obj = {}
      for (let idx in list) {
        const item = list[idx]
        obj[idx] = item && item.map((v) => v.commonId)
      }
      this.form.newFileIds = obj
    },
    //限制开始时间
    disabledDateStart(current) {
      let dateEnd = this.form.expectedEndDate;
      if (dateEnd) {
        return current > moment(dateEnd).endOf('day');
      }
    },
    //限制结束时间
    disabledDateEnd(current) {
      let dateStart = this.form.expectedStartDate;
    if (dateStart) {
      return (
        (current && current < moment(dateStart).subtract(1, 'days').endOf('day'))
      );
    }
  },
   //二次报审限制开始时间
   disabledDateStart2(current){
      let dateEnd = this.changeForm.implementationEndDate;
      if (dateEnd) {
        return current > moment(dateEnd).endOf('day');
      }
    },
  //二次报审限制结束时间
   disabledDateEnd2(current) {
      let dateStart = this.changeForm.implementationDate;
    if (dateStart) {
      return (
        (current &&
          current < moment(dateStart).subtract(1, 'days').endOf('day'))
      );
    }
  }
  }
}
</script>

<style lang="less">
@deep: ~'>>>';
.technical-use-component {
  padding: 0 !important;
  .content-bx{
    height: auto !important;
    padding-right: 0 !important;
  }
}
.foot-btn {
  display: flex;
  justify-content: flex-end;
}
.radio-box {
  .ant-radio-wrapper {
    position: static !important;
  }
  .ant-radio-group {
    margin-top: 3% !important;
    display: flex;
  }
}
.title {
  border-left: 4px solid #1890ff;
  font-weight: bold;
  font-size: 14px;
  margin-bottom: 20px;
  padding-left: 10px;
  height: 18px;
  line-height: 20px;
  margin-left: 20px;
  margin-top: 20px;
}
.customtable {
  width: 100%;
  border: 1px solid gainsboro;

  thead {
    background: rgb(244, 244, 244);

    th {
      padding: 10px;
      border: 1px solid gainsboro;
    }
  }

  tbody {
    td {
      padding: 10px;
      border: 1px solid gainsboro;
    }
  }
}
.table-page-search-wrapper{
   .requireX::before{
    display: inline-block;
    color: #f5222d;
    font-size: 14px;
    font-family: SimSun, sans-serif;
    line-height: 1;
    content: '*';
  }
 .planSelection-class{
 .ant-form-item-children{
    position: relative;
    display: flex;
    .BaseInput-container{
      width: 91%;
    }
   }
   .ant-btn{
      position: absolute;
      right: -40px;
      top: 0;
      flex: 1;
      z-index: 100;
    }
}
.ant-input-disabled{
  background-color: #F5F5F5!important;
  border:1px solid #d9d9d9!important;
}
}
.dangerProjectType{
  max-height: 100px;
  overflow: scroll;
}
</style>
